import 'package:animated_transitions/animated_transitions.dart';
import 'package:flutter/material.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:vamos/view/system/auth_page.dart';

/// 需要登录的弹窗组件
/// 当用户点击需要登录的功能时，如果未登录则显示此弹窗
class VamosLoginRequiredDialog extends StatelessWidget {
  const VamosLoginRequiredDialog({super.key});

  /// 显示需要登录的弹窗
  static Future<void> showLoginRequiredDialog(BuildContext context) {
    return showDialog<void>(
      context: context,
      barrierDismissible: true,
      builder: (BuildContext context) {
        return const VamosLoginRequiredDialog();
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: Colors.transparent,
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: 24.w),
        padding: EdgeInsets.all(24.w),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(16.r),
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.1),
              blurRadius: 20,
              offset: Offset(0, 10),
            ),
          ],
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            // 图标
            Container(
              width: 60.w,
              height: 60.w,
              decoration: BoxDecoration(
                color: Colors.orange.withOpacity(0.1),
                shape: BoxShape.circle,
              ),
              child: Icon(Icons.lock_outline, size: 30.w, color: Colors.orange),
            ),

            SizedBox(height: 20.h),

            // 标题
            Text('Login Required')
                .fontSize(20.sp)
                .bold()
                .textColor(Colors.black)
                .textAlignment(TextAlign.center),

            SizedBox(height: 12.h),

            // 描述文本
            Text(
                  'You need to login to access this feature. Please login to continue.',
                )
                .fontSize(14.sp)
                .textColor(Colors.grey[600])
                .textAlignment(TextAlign.center),

            SizedBox(height: 24.h),

            // 按钮组
            Row(
              children: [
                // 取消按钮
                Expanded(
                  child: Container(
                    height: 44.h,
                    decoration: BoxDecoration(
                      color: Colors.grey[100],
                      borderRadius: BorderRadius.circular(8.r),
                    ),
                    child: Text('Cancel')
                        .fontSize(14.sp)
                        .textColor(Colors.grey[600])
                        .center()
                        .inkWell(
                          onTap: () {
                            Navigator.of(context).pop();
                          },
                        ),
                  ),
                ),

                SizedBox(width: 12.w),

                // 登录按钮
                Expanded(
                  child: Container(
                    height: 44.h,
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        colors: [Colors.orange, Colors.deepOrange],
                        begin: Alignment.centerLeft,
                        end: Alignment.centerRight,
                      ),
                      borderRadius: BorderRadius.circular(8.r),
                    ),
                    child: Text('Login')
                        .fontSize(14.sp)
                        .bold()
                        .textColor(Colors.white)
                        .center()
                        .inkWell(
                          onTap: () {
                            Navigator.of(context).pop();
                            _navigateToLoginPage(context);
                          },
                        ),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  /// 导航到登录页面
  void _navigateToLoginPage(BuildContext context) {
    Navigator.of(context).push(
      TransitionPageRoute(
        builder: (context) => UserAuthPage(),
        transitionAnimation: DirectionalPixelatedTransition(
          duration: const Duration(milliseconds: 600),
          colors: [Color(0xFF83BE4A), Color(0xFFF3E3C6), Color(0xFFFB894E)],
        ),
      ),
    );
  }
}
